﻿namespace ch07.binary.interpreter
{
    public static partial class Instr
    {
        private static void localGet(ref Vm vm, object args)
        {
            var idx = (uint) args;
            var val = vm.GetOperand(vm.Local0Idx + idx);
            vm.PushU64(val);
        }

        private static void localSet(ref Vm vm, object args)
        {
            var idx = (uint) args;
            var val = vm.PopU64();
            vm.OperandStack.setOperand(vm.Local0Idx + idx, val);
        }

        private static void localTee(ref Vm vm, object args)
        {
            var idx = (uint) args;
            var val = vm.PopU64();
            vm.PushU64(val);
            vm.OperandStack.setOperand(vm.Local0Idx + idx, val);
        }

        private static void globalGet(ref Vm vm, object args)
        {
            var idx = (uint) args;
            var val = vm.Globals[idx].GetAsU64();
            vm.PushU64(val);
        }

        private static void globalSet(ref Vm vm, object args)
        {
            var idx = (uint) args;
            var val = vm.PopU64();
            vm.Globals[idx].SetAsU64(val);
        }
    }
}